﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyRaceGame.GameLogic
{
    public class AIRacerCharacter : RacerDecorator
    {
        public AIRacerCharacter(RacerCharacter racerCharacter, RaceController raceData)
            : base(racerCharacter)
        {
            this.raceData = raceData;
            randomizer = new Random();
        }

        protected override void ExtraUpdate(Microsoft.Xna.Framework.GameTime gameTime)
        {
            if (!raceData.RaceFinished)
                catchup();
        }

        void catchup()
        {
            float acc = (float)randomizer.NextDouble() * 
                (raceData.HumanRacer.TotalTrackLength / raceData.HumanRacer.RaceTrack.TrackLength - TotalTrackLength
                / RaceTrack.TrackLength) * catchupFactor;

            if (Speed + acc > raceData.HumanRacer.RaceTrack.TrackLength / 16 && 
                Speed + acc <= raceData.HumanRacer.RaceTrack.TrackLength / 8)
                Speed += acc;
        }

        RaceController raceData;
        Random randomizer;
        static float catchupFactor = 2f;
    }
}
